package com.whjz.dcfs.jzxx.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.whjz.dcfs.jzxx.model.DcfsHjjcdJbxx;
import com.whjz.dcfs.util.PageParam;

@Repository
public class DcfsHjjcdJbxxDAO implements IDcfsHjjcdJbxxDAO{

    @Autowired
    private SqlMapClient sqlMapClient;

    public void deleteDcfsHjjcdJbxxByCond(DcfsHjjcdJbxx object) throws SQLException{
        sqlMapClient.delete("deleteDcfsHjjcdJbxxByCond", object);
    }

    public void deleteDcfsHjjcdJbxxListByCond(List<DcfsHjjcdJbxx> list) throws SQLException{
        if (null != list) {
			sqlMapClient.startBatch();
            for (int i = 0; i < list.size(); i++) {
                deleteDcfsHjjcdJbxxByCond(list.get(i));
            }
			sqlMapClient.executeBatch();
        }
    }

    public List<DcfsHjjcdJbxx> getDcfsHjjcdJbxxListByCond(DcfsHjjcdJbxx object) throws SQLException{
        return sqlMapClient.queryForList("getDcfsHjjcdJbxxByCond", object);
    }

    public PageParam queryPageInfo(DcfsHjjcdJbxx object,PageParam pageParam) throws SQLException{
		pageParam.setPageIndex(pageParam.getPageIndex());
		object.setPageIndex(pageParam.getPageIndex());
		object.setPageLast(pageParam.getPageLast());
		int totalCount = ((Integer)sqlMapClient.queryForObject("queryDcfsHjjcdJbxxCount",object)).intValue();
		List<DcfsHjjcdJbxx> list = sqlMapClient.queryForList("queryDcfsHjjcdJbxxPage",object);
		pageParam.setResult(list);
		pageParam.setTotalCount(totalCount);
		pageParam.setTotalPage(pageParam.getTotalPage());
		return pageParam;
    }

	public void insertDcfsHjjcdJbxx(DcfsHjjcdJbxx object) throws SQLException {
		sqlMapClient.insert("insertDcfsHjjcdJbxx", object);
	}

	public void updateDcfsHjjcdJbxx(DcfsHjjcdJbxx object) throws SQLException {
		sqlMapClient.update("updateDcfsHjjcdJbxx", object);
	}

	public List<DcfsHjjcdJbxx> getDcfsHjjcdJbxxByCond_time(DcfsHjjcdJbxx object)
			throws SQLException {
		return sqlMapClient.queryForList("getDcfsHjjcdJbxxByCond_time", object);
	}
	public List<DcfsHjjcdJbxx> getDcfsHjjcdJbxxByCond_timeNew(DcfsHjjcdJbxx object)
			throws SQLException {
		return sqlMapClient.queryForList("getDcfsHjjcdJbxxByCond", object);
	}
	public List<DcfsHjjcdJbxx> getDcfsHjjcdJbxxByCond_sb(DcfsHjjcdJbxx object)
			throws SQLException {
		ResultSet rs=null;
		String sql="select distinct jz_sb_bh from dcfs_hjjcd_jbxx      where   1=1  ";
		if(object!=null&&!object.getJcdmc().equals("")){
			sql+=" and jcd_mc like '%"+object.getJcdmc()+"%'";
		}
		if(object!=null&&!object.getHjzljkdz().equals("")){
			sql+=" and hjzl_jk_dz like '%"+object.getHjzljkdz()+"%'";
		}
//    	System.out.println(sql);
    	List<DcfsHjjcdJbxx> list=new ArrayList<DcfsHjjcdJbxx>();
    	Connection conn=sqlMapClient.getDataSource().getConnection();
    	try{
    		rs=conn.prepareStatement(sql).executeQuery();
    		while(rs.next()){
    			DcfsHjjcdJbxx model=new DcfsHjjcdJbxx();
    			model.setJzsbbh(rs.getString("jz_sb_bh"));
    			list.add(model);
    		}
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    	return list;
	}

	@Override
	public List<HashMap> findXzqy(DcfsHjjcdJbxx object) throws SQLException {
		return sqlMapClient.queryForList("findXzqy",object);
	}
}
